// pages/tests/tests.js
const date = new Date()
const years = []
const months = []
const days = []

for (let i = 1990; i <= date.getFullYear(); i++) {
  years.push(i)
}

for (let i = 1 ; i <= 12; i++) {
  months.push(i)
}

for (let i = 1 ; i <= 31; i++) {
  days.push(i)
}
var interval;
var varName;
var ctx = wx.createCanvasContext('canvasArcCir');
Page({ 
 data: { 
    nullHouse:true,  //先设置隐藏
   pics:[],
   selectPerson:true,
    firstPerson:'个人',
    selectArea:false,
    showModalStatus: false,
     years: years,
    year: date.getFullYear(),
    months: months,
    month: 2,
    days: days,
    day: 2,
    year: date.getFullYear(),
    value: [9999, 1, 1],
      touchObj:{
          id:'',//被滑动元素标识
          sX:'',//开始滑动水平方向位置
          sY:'',//开始滑动竖直方向位置
          eX:'',//结束滑动水平方向位置
          eY:'',//结束滑动竖直方向位置
          difX:'',//水平方向差值
          difY:'',//竖直方向差值
          isSwapLeft:false//是否触发滑动
      },

    province: '省',  
    city: '市',  
    district: '区',  
    arrayProvince: [],  
    arrayCity: [],  
    arrayDistrict: [],  
    indexProvince: 0,  
    indexCity: 0,  
    IndexDistrict: 0,  
    citylist1: [],  
 }, 
drawCircle: function () {
    clearInterval(varName);
    function drawArc(s, e) {
      ctx.setFillStyle('white');
      ctx.clearRect(0, 0, 200, 200);
      ctx.draw();
      var x = 100, y = 100, radius = 96;
      ctx.setLineWidth(5);
      ctx.setStrokeStyle('#d81e06');
      ctx.setLineCap('round');
      ctx.beginPath();
      ctx.arc(x, y, radius, s, e, false);
      ctx.stroke()
      ctx.draw()
    }
    var step = 1, startAngle = 1.5 * Math.PI, endAngle = 0;
    var animation_interval = 1000, n = 60;
    var animation = function () {
      if (step <= n) {
        endAngle = step * 2 * Math.PI / n + 1.5 * Math.PI;
        drawArc(startAngle, endAngle);
        step++;
      } else {
        clearInterval(varName);
      }
    };
    varName = setInterval(animation, animation_interval);
  },
 clickArea:function(){
   var that = this;
   that.setData({
    nullHouse:false //弹窗显示
    }) ;
   setTimeout(function(){
    //that.data.nullHouse = true; //1秒之后弹窗隐藏
        that.setData({
          nullHouse:false //弹窗显示
        }) ;
     },1000);
  },



 //点击选择类型
  clickPerson:function(){
    var selectPerson = this.data.selectPerson;
    if(selectPerson == true){
     this.setData({
     selectArea:true,
     selectPerson:false,
  })
    }else{
     this.setData({
     selectArea:false,
     selectPerson:true,
  })
    }
  } ,
  //点击切换
  mySelect:function(e){
   this.setData({
     firstPerson:e.target.dataset.me,
     selectPerson:true,
     selectArea:false,
   })
  },
 bindChange: function(e) {
    const val = e.detail.value
    this.setData({
      year: this.data.years[val[0]],
      month: this.data.months[val[1]],
      day: this.data.days[val[2]]
    })
  },
 powerDrawer: function (e) { 
    var currentStatu = e.currentTarget.dataset.statu; 
    this.util(currentStatu) 
 }, 
 util: function(currentStatu){ 
    /* 动画部分 */
    // 第1步：创建动画实例 
    var animation = wx.createAnimation({ 
    duration: 200, //动画时长 
    timingFunction: "linear", //线性 
    delay: 0 //0则不延迟 
    }); 
    
    // 第2步：这个动画实例赋给当前的动画实例 
    this.animation = animation; 
    
    // 第3步：执行第一组动画 
    animation.opacity(0).rotateX(-100).step(); 
    
    // 第4步：导出动画对象赋给数据对象储存 
    this.setData({ 
        animationData: animation.export() 
    }) 
    
    // 第5步：设置定时器到指定时候后，执行第二组动画 
    setTimeout(function () { 
    // 执行第二组动画 
        animation.opacity(1).rotateX(0).step(); 
        // 给数据对象储存的第一组动画，更替为执行完第二组动画的动画对象 
        this.setData({ 
            animationData: animation 
        }) 
        
        //关闭 
        if (currentStatu == "close") { 
            this.setData( 
            { 
            showModalStatus: false
            } 
            ); 
        } 
    }.bind(this), 200) 
    
    // 显示 
    if (currentStatu == "open") { 
        this.setData( 
        { 
        showModalStatus: true
        } 
    ); 
    } 
 } ,
 onReady: function () {
    //创建并返回绘图上下文context对象。
    var cxt_arc = wx.createCanvasContext('canvasCircle');
    cxt_arc.setLineWidth(6);
    cxt_arc.setStrokeStyle('#eaeaea');
    cxt_arc.setLineCap('round');
    cxt_arc.beginPath();
    cxt_arc.arc(100, 100, 96, 0, 2 * Math.PI, false);
    cxt_arc.stroke();
    cxt_arc.draw();
  },

  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
  },
  uppd:function(e){
   var that=this,
　　pics=this.data.pics;
      wx.chooseImage({
           count: 9-pics.length, // 最多可以选择的图片张数，默认9
           sizeType: ['original', 'compressed'], // original 原图，compressed 压缩图，默认二者都有
           sourceType: ['album', 'camera'], // album 从相册选图，camera 使用相机，默认二者都有
           success: function(res){
           var imgsrc=res.tempFilePaths; 
　　　　　　pics=pics.concat(imgsrc);  
            that.setData({
                pics:pics
            });
      },
      fail: function() {
        // fail
      },
      complete: function() {
        // complete
      }
    });
  },
   luploadimg:function(){//这里触发图片上传的方法
       var pics=this.data.pics;
       let rootUrl = httptool.getRootUrl();
       app.uploadimg({
           url: rootUrl + 'api/ImgUpload/ImgUpload',//这里是你图片上传的接口
           path:pics,//这里是选取的图片的地址数组
           name: 'file',
        });
  },

})